import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '@core/base/auth.service';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import { Observable } from 'rxjs';

@Component({
	selector: 'app-welcome',
	templateUrl: './welcome.component.html',
	styleUrls: ['./welcome.component.less']
})
export class WelcomeComponent {
	html = ``;

	isAuthenticated$: Observable<boolean>;
	isDoneLoading$: Observable<boolean>;
	canActivateProtectedRoutes$: Observable<boolean>;
	constructor(
		protected router: Router,
		protected noticSrc: NzNotificationService,
		private authService: AuthService,
	) {
		this.isAuthenticated$ = this.authService.isAuthenticated$;
		this.isDoneLoading$ = this.authService.isDoneLoading$;
		this.canActivateProtectedRoutes$ = this.authService.canActivateProtectedRoutes$;
	}

	login() { this.authService.login(); }
	logout() { this.authService.logout(); }
	refresh() { this.authService.refresh(); }
	reload() { window.location.reload(); }
	clearStorage() { localStorage.clear(); }

	logoutExternally() {
		window.open(this.authService.logoutUrl);
	}

	get hasValidToken() { return this.authService.hasValidToken(); }
	get accessToken() { return this.authService.accessToken; }
	get refreshToken() { return this.authService.refreshToken; }
	get identityClaims() { return this.authService.identityClaims; }
	get idToken() { return this.authService.idToken; }
}
